<!--
 * @description: 
 * @Date: 2022-10-08 14:41:00
 * @LastEditTime: 2022-11-23 22:07:48
-->
<template>
  <div :class="(store.state.editStatus ? 'edits' : '') + ' item filter ' + gridRc">
    <div class="itemBox" @contextmenu.prevent="menu($event, item)" v-animate="'bounceIn'">
      <img
        v-if="store.state.editStatus"
        @click.stop="del(item)"
        class="del-footer"
        src="@/assets/svg/close.svg"
      />
      <section class="comp">
        <C :data="item"></C>
      </section>
      <div class="names">{{ item.name }}</div>
    </div>
  </div>
</template>
<script setup>
import { ref, watch, defineProps, defineAsyncComponent } from "vue";
import { useStore } from "vuex";
import emitter from "../util/emitter";
const store = useStore();
const props = defineProps({
  info: {
    type: Object,
  },
});
const { size = "1x1", component } = props.info; //默认尺寸1x1
const del = (item) => {
  store.commit("delLink", item.id);
};

let C = defineAsyncComponent(() => import(`./plugin/${component}.vue`));
const gridRc = ref("c" + size);
const item = ref(props.info);
watch(props.info, (w) => {
  gridRc.value = "c" + w.size;
  item.value = w;
});
const menu = (event, info) => {
  const { button, clientX, clientY } = event;
  if (button === 2) {
    emitter.emit("mousePs", {
      left: clientX,
      top: clientY,
      data: info,
    });
  }
  event.stopPropagation();
};
</script>
<style lang="less" scoped>
.item {
  transform: translateZ(0);
  transition: all 0.2s;
}

.c1x1 {
  width: 60px;
  height: 80px;
  grid-row: span 1 / span 1;
  grid-column: span 1 / span 1;
}

.c2x2 {
  width: 145px;
  height: 177px;
  grid-row: span 2 / span 2;
  grid-column: span 2 / span 2;
}

.c2x4 {
  width: 323px;
  height: 177px;
  grid-row: span 2 / span 2;
  grid-column: span 4 / span 4;
}

.itemBox {
  height: 100%;
  transition: all 0.5s;
  .del-footer {
    position: absolute;
    right: -8px;
    top: -8px;
    width: 16px;
    height: 16px;
    background: rgba(212, 212, 212, 0.651);
    cursor: pointer;
    z-index: 10;
    border-radius: 20px;
    transition: all 0.2s;

    // &:hover {
    //   transform: scale(1.5);
    // }
  }

  > .comp {
    position: relative;
    width: 100%;
    height: calc(100% - 20px);
    border-radius: var(--iconRadius);
    box-shadow: 0 0 5px #0000002c;
    overflow: hidden;
  }

  > .names {
    margin-top: 6px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    color: #fff;
    font-size: 12px;
    text-align: center;
    filter: drop-shadow(0px 3px 3px rgba(0, 0, 0, 0.3));
  }
}
</style>
